package com.coderman.basketball.infrast.mq.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Description:
 * date: 2021/5/25
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Service
public class MqProducer {
    public static final Logger LOGGER = LoggerFactory.getLogger(MqProducer.class);

    public static final String TOPIC = "basketball_plat";

    @Autowired
    private DefaultMQProducer defaultMQProducer;

    /**
     * 发送mq消息
     * @param msg
     * @param tag
     */
    public void sendMsg(String msg,String tag){
        Message message = new Message(TOPIC, tag, msg.getBytes());
        try {
            defaultMQProducer.send(message);
        } catch (MQClientException e) {
            e.printStackTrace();
        } catch (RemotingException e) {
            e.printStackTrace();
        } catch (MQBrokerException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



}
